import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pp_uikit/pp_uikit.dart';

class DemoImageSelector extends StatelessWidget {
  DemoImageSelector({Key? key}) : super(key: key);

  var imageList = <PPImageModel>[].obs;
  var imageList2 = <PPImageModel>[].obs;
  var content = "".obs;
  var controller = PPImageSelectorController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("ImageSelector"),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: [
              PPButton(
                "打印当前选中的图片",
                height: 60,
                onPressed: () {
                  content.value = "call controller.getImagesModel() =\n\n";
                  // var list = controller.getImagesModel();
                  var list = imageList;
                  for (var item in list) {
                    content.value += "${item.url}".split('/').last;
                    content.value += "\n";
                  }
                },
              ),
              const Text(
                  "PPImageSelector\n--------\ndraggable: true\n--------"),
              Obx(() => PPImageSelector(
                    controller: controller,
                    imagesList: imageList,
                    draggable: true,
                    // rowCount: 3,
                    onDeleteTap: (model) {
                      debugPrint(
                          "PPImageSelector onDeleteImage model = $model");
                    },
                    onItemTap: (model) {
                      debugPrint(
                          "PPImageSelector onItemTap model.url = ${model.url}");
                    },
                    onItemsChanged: (list) {
                      imageList.clear();
                      imageList.addAll(list);
                      debugPrint(
                          "PPImageSelector onItemsChanged length = ${imageList.length}");
                      for (var item in imageList) {
                        print(item.url);
                      }
                    },
                  )),
              Obx(() => PPImageSelector(
                    controller: controller,
                    imagesList: imageList2,
                    draggable: true,
                    maxCount: 50,
                    // rowCount: 3,
                    onDeleteTap: (model) {
                      debugPrint(
                          "PPImageSelector2 onDeleteImage model = $model");
                    },
                    onItemTap: (model) {
                      debugPrint(
                          "PPImageSelector2 onItemTap model.url = ${model.url}");
                    },
                    onItemsChanged: (list) {
                      imageList2.clear();
                      imageList2.addAll(list);
                      debugPrint(
                          "PPImageSelector2 onItemsChanged length = ${imageList2.length}");
                      for (var item in imageList2) {
                        print(item.url);
                      }
                    },
                  )),
              Obx(() => Text("$content")),
            ],
          ),
        ));
  }
}
